const app = getApp();
var api = require('../../../api.js');
var WxParse = require('../../../wxParse/wxParse.js');
var mta = require('../../../mta_analysis.js');

Page({
  data: {
    list: 'XXX',
    article: '111',
  },
  onLoad: function (options) {
  //   console.log("——————————————onLoad————————————————");
  //   console.log(options);
  //   console.log(options.str);
  //   var that = this;
  //   let list = JSON.parse(options.str);
  //   var temp = WxParse.wxParse('article1', 'html', list, that, 5);
  //   that.setData({
  //     list: list,
  //     article: temp,
  //   })
    this.getArticle();
    mta.Page.init();
  },
  onReady: function () {
  
  },
  onShow: function () {
  
  },
  onHide: function () {
    var url = app.getcurrentPage();
    wx.setStorageSync("from_url", url);
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
    this.getArticle();
    // 显示顶部刷新图标  
    wx.showNavigationBarLoading();

    // 隐藏导航栏加载框  
    wx.hideNavigationBarLoading();

    //停止下拉刷新
    wx.stopPullDownRefresh();
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
    // var url = app.getcurrentPage();
    // var user_id = wx.getStorageSync('user_id');
    // return {
    //   path: url + "?user_id=" + user_id,
    //   title: '得道1314'
    // };  
    wx.hideShareMenu()
  },
  back: function (e) {
    wx.navigateBack({
      delta: 1
    })
  },
  getArticle: function (e) {
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    var url = api.user.article;
    wx.request({
      url: url,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        article_cat_id: 3,
      },
      success: function (e) {
        console.log("————————————————————道财说明————————————————");
        // console.log(e);
        // var article = e.data.data.article;
        // console.log(article);
        // let str = JSON.stringify(article);
        // console.log(str);
        var article = e.data.data.article;
        console.log(e);
        console.log(article);
        var temp = WxParse.wxParse('article1', 'html', article, that, 5);
        that.setData({
          article: temp,
        })
      }
    });
  }
})